<!DOCTYPE html>
<html>
<head>
  <link rel="icon" href="basic-48.png">
  <script>
    'use strict';

    async function share_text(text) {
      try {
        await navigator.share({text: text});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    function create_file(name, content_type, length) {
      const contents = ['*'.repeat(length)];
      const options = {type: content_type};
      return new File(contents, name, options);
    }

    async function share_single_file() {
      try {
        const single_file = create_file('sample.webp', 'image/webp', 12);
        await navigator.share({files: [single_file]});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_multiple_files() {
      try {
        const first_file = create_file('sam.ple.mp3', 'audio/mpeg', 345);
        const second_file = create_file('../sample.mp4', 'video/mp4', 67890);
        const third_file = create_file('sam\\ple.gif', 'image/gif', 1)
        await navigator.share({files: [first_file, second_file, third_file]});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_title() {
      try {
        await navigator.share({title: "Subject"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_title_url() {
      try {
        await navigator.share({title: "Subject",
                               url: "https://example.com/"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_text() {
      try {
        await navigator.share({text: "Message"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_text_url() {
      try {
        await navigator.share({text: "Message",
                               url: "https://example.com/"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_url() {
      try {
        await navigator.share({url: "https://example.com/"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_file_title() {
      try {
        const single_file = create_file('sample.webp', 'image/webp', 12);
        await navigator.share({files: [single_file], title: "Subject"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_file_title_url() {
      try {
        const single_file = create_file('sample.webp', 'image/webp', 12);
        await navigator.share({files: [single_file],
                               title: "Subject",
                               url: "https://example.com/"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_file_text() {
      try {
        const single_file = create_file('sample.webp', 'image/webp', 12);
        await navigator.share({files: [single_file], text: "Message"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_file_text_url() {
      try {
        const single_file = create_file('sample.webp', 'image/webp', 12);
        await navigator.share({files: [single_file],
                               text: "Message",
                               url: "https://example.com/"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_file_url() {
      try {
        const single_file = create_file('sample.webp', 'image/webp', 12);
        await navigator.share({files: [single_file],
                               url: "https://example.com/"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_multiple_custom_files_url(first_filename, second_filename) {
      try {
        const first_file = create_file(first_filename, 'text/csv', 12);
        const second_file = create_file(second_filename, 'text/csv', 15);
        await navigator.share({files: [first_file, second_file],
                               url: "https://example.com/"});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

    async function share_pdf_file() {
      try {
        const pdf_file = create_file('sample.pdf', 'application/pdf', 12);
        await navigator.share({files: [pdf_file]});
        return 'share succeeded';
      } catch(error) {
        return ('share failed: ' + error);
      }
    }

  </script>
</head>
<body>
</body>
</html>
